<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>数组</title>
</head>
<body>
    <script>
       // 直接赋值
       var arr1 = [1,2,3,4,5];
       console.log(arr1);
       // 创建对象赋值
       var array = new Array(5);
       console.log(array);

       // 数组常用属性
       // 获取长度
       var length = array.length;
       console.log(length);
       // 数组长度可变
       var number = array.length--;
       console.log(array);
       // 索引操作元素
       arr1[1] = "yft"
       console.log(arr1);
       // 遍历数组
       for (let i = 0; i < arr1.length; i++) {
         console.log(arr1[i]);
       }

       for (let i = arr1.length - 1; i >= 0; i--) {
         console.log(arr1[i]);
       }

       // 数组添加方法 push
       var number1 = arr1.push("6");
       console.log(number1);
       console.log(arr1);

       // 首端添加
       var number2 = arr1.unshift("6");
       console.log(number2);
       console.log(arr1);

       // 删除元素 // pop 删除尾部元素
       var number3 = arr1.pop();
       console.log(number3);
       console.log(arr1);
       // 删除首端元素
       var number4 = arr1.shift();
       console.log(number4);
       console.log(arr1);

       // 删除 添加 替换 三合一
       /*
            arr1.splice(1,1,"wl" , "hpy" , "cjx")
            1代表起始元素 第二个1代表受影响的元素 第三个位置代表要添加的元素 == 替换
            arr1.splice(1,0,"wl" , "hpy" , "cjx") == 添加
            arr1.splice(1,1) == 删除
       */
       var numbers = arr1.splice(1,1,"wl" , "hpy" , "cjx");
       console.log(numbers);
       console.log(arr1);
       var numbers1 = arr1.splice(1,1);
       console.log(numbers1);
       console.log(arr1);
    </script>
</body>
</html>